package Views;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;

import javax.swing.JPanel;
import javax.swing.JButton;
import java.awt.GridLayout;
import java.util.ArrayList;

import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.SwingConstants;

import Models.Recipe;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.SystemColor;
import javax.swing.ScrollPaneConstants;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import javax.swing.BoxLayout;
import java.awt.Insets;
import net.miginfocom.swing.MigLayout;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.SpringLayout;
import com.jgoodies.forms.layout.FormLayout;
import com.jgoodies.forms.layout.ColumnSpec;
import com.jgoodies.forms.layout.RowSpec;
import com.jgoodies.forms.factories.FormFactory;
import java.awt.CardLayout;

public class GridBag_RecipeView extends JPanel implements ActionListener {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;	

	//use to populate JLabels, and keep track of text boxes
	public static final String[] recipeFields = {"Name", "Style", "OG", "FG", "IBU", "Pre Boil Volume", 
													"Post Boil Volume", "Boil Time", "Mash Temp", "Mash Time", 
													"Efficiency", "Brew Date"};
	
	
	private MainWindow parent;
	
	JPanel viewPanel; //TODO REMOVE
	JPanel panel;
	JPanel panel_1;
	

	/**
	 * Create the panel.
	 */
	public GridBag_RecipeView(MainWindow parent) {
		this.parent = parent;
		
		setBackground(Color.WHITE);
		setLayout(new BorderLayout(0, 0));
		

		createButtons();
	}
	
	/**
	 * Draws all of the buttons, JLabels, and any other component needed for editing the
	 * editCurrentRecipePanel
	 */
	private void drawEdit() {
		//TODO creates a new jpanel & draws everything to it, set to disabled
	}
	
	/**
	 * Draws all of the buttons and JLabels for the current recipe panel
	 */
	private void drawDefault() {
		//TODO creates a new JPanel & draws everything on it, set to enabled
	}
	
	private void refreshParentPanel() {
		//TODO
	}
	
	private void refreshCurrentDefaultPanel() {
		//TODO
	}
	
	private void refreshCurrentEditPanel() {
		//TODO
	}
	
	private void refreshDefaultButtons() {
		//TODO
	}
	
	private void refreshEditButtons() {
		
	}
	
	/**
	 * Displays the default recipe view
	 */
	private void displayDefaultView() {
		//TODO
	}
	
	private void displayEditView() {
		
	}
	
	private void updateRecipes() {
		//TODO
	}
	
	private void refreshRecipes() {
		//TODO
	}
	
	private void reBrew() {
		//TODO
	}
	
	private void newRecipe() {
		//TODO
	}
	
	private void editRecipe() {
		//TODO
	}
	
	private void deleteRecipe() {
		//TODO
	}
	
	
	
	
	
	
	
	private void createButtons() {
		JPanel pnlButton = new JPanel();
		pnlButton.setBackground(SystemColor.menu);
		add(pnlButton, BorderLayout.SOUTH);
		pnlButton.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
		
		JButton btnReBrew = new JButton("Re-Brew");
		pnlButton.add(btnReBrew);
		
		JButton btnNew = new JButton("New");
		btnNew.addActionListener(this);
		pnlButton.add(btnNew);
		
		JButton btnEdit = new JButton("Edit");
		pnlButton.add(btnEdit);
		
		JButton btnDelete = new JButton("Delete");
		pnlButton.add(btnDelete);
		
		JPanel topPanel = new JPanel();
		add(topPanel, BorderLayout.NORTH);
		
		JLabel lblCurrent = new JLabel("Current");
		topPanel.add(lblCurrent);
		
		JLabel lblParent = new JLabel("Parent");
		topPanel.add(lblParent);
		
		JScrollPane viewScroller = new JScrollPane();
		viewScroller.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
		add(viewScroller, BorderLayout.CENTER);
		
		viewPanel = new JPanel();
		viewPanel.setBackground(Color.WHITE);
		viewScroller.setViewportView(viewPanel);
		viewPanel.setLayout(new CardLayout(0, 0));

		
		panel_1 = new JPanel();
		viewPanel.add(panel_1, "panel1");
		
		JLabel lblNewLabel = new JLabel("New label");
		panel_1.add(lblNewLabel);
		
		panel = new JPanel();

		viewPanel.add(panel, "panel");
		GridBagLayout gbl_panel = new GridBagLayout();
		gbl_panel.columnWidths = new int[]{214, 214, 0};
		gbl_panel.rowHeights = new int[]{39, 39, 39, 39, 0, 39, 39, 39, 0, 0, 0};
		gbl_panel.columnWeights = new double[]{0.0, 0.0, Double.MIN_VALUE};
		gbl_panel.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
		panel.setLayout(gbl_panel);
		
				
				JButton btnNewButton = new JButton("New button");
				GridBagConstraints gbc_btnNewButton = new GridBagConstraints();
				gbc_btnNewButton.fill = GridBagConstraints.BOTH;
				gbc_btnNewButton.insets = new Insets(0, 0, 5, 5);
				gbc_btnNewButton.gridx = 0;
				gbc_btnNewButton.gridy = 0;
				panel.add(btnNewButton, gbc_btnNewButton);
		
		JButton btnNewButton_1 = new JButton("New button");
		GridBagConstraints gbc_btnNewButton_1 = new GridBagConstraints();
		gbc_btnNewButton_1.fill = GridBagConstraints.BOTH;
		gbc_btnNewButton_1.insets = new Insets(0, 0, 5, 0);
		gbc_btnNewButton_1.gridx = 1;
		gbc_btnNewButton_1.gridy = 0;
		panel.add(btnNewButton_1, gbc_btnNewButton_1);
		
		JButton btnNewButton_9 = new JButton("New button");
		GridBagConstraints gbc_btnNewButton_9 = new GridBagConstraints();
		gbc_btnNewButton_9.fill = GridBagConstraints.BOTH;
		gbc_btnNewButton_9.insets = new Insets(0, 0, 5, 5);
		gbc_btnNewButton_9.gridx = 0;
		gbc_btnNewButton_9.gridy = 1;
		panel.add(btnNewButton_9, gbc_btnNewButton_9);
		
		JButton btnNewButton_8 = new JButton("New button");
		GridBagConstraints gbc_btnNewButton_8 = new GridBagConstraints();
		gbc_btnNewButton_8.fill = GridBagConstraints.BOTH;
		gbc_btnNewButton_8.insets = new Insets(0, 0, 5, 0);
		gbc_btnNewButton_8.gridx = 1;
		gbc_btnNewButton_8.gridy = 1;
		panel.add(btnNewButton_8, gbc_btnNewButton_8);
		
		JLabel label = new JLabel("");
		GridBagConstraints gbc_label = new GridBagConstraints();
		gbc_label.fill = GridBagConstraints.BOTH;
		gbc_label.insets = new Insets(0, 0, 5, 5);
		gbc_label.gridx = 0;
		gbc_label.gridy = 2;
		panel.add(label, gbc_label);
		
		JButton btnNewButton_3 = new JButton("New button");
		GridBagConstraints gbc_btnNewButton_3 = new GridBagConstraints();
		gbc_btnNewButton_3.fill = GridBagConstraints.BOTH;
		gbc_btnNewButton_3.insets = new Insets(0, 0, 5, 0);
		gbc_btnNewButton_3.gridx = 1;
		gbc_btnNewButton_3.gridy = 2;
		panel.add(btnNewButton_3, gbc_btnNewButton_3);
		
		JButton btnNewButton_2 = new JButton("New button");
		GridBagConstraints gbc_btnNewButton_2 = new GridBagConstraints();
		gbc_btnNewButton_2.fill = GridBagConstraints.BOTH;
		gbc_btnNewButton_2.insets = new Insets(0, 0, 5, 5);
		gbc_btnNewButton_2.gridx = 0;
		gbc_btnNewButton_2.gridy = 3;
		panel.add(btnNewButton_2, gbc_btnNewButton_2);
		
		JLabel label_1 = new JLabel("");
		GridBagConstraints gbc_label_1 = new GridBagConstraints();
		gbc_label_1.fill = GridBagConstraints.BOTH;
		gbc_label_1.insets = new Insets(0, 0, 5, 0);
		gbc_label_1.gridx = 1;
		gbc_label_1.gridy = 3;
		panel.add(label_1, gbc_label_1);
		
		JButton btnNewButton_7 = new JButton("New button");
		GridBagConstraints gbc_btnNewButton_7 = new GridBagConstraints();
		gbc_btnNewButton_7.fill = GridBagConstraints.BOTH;
		gbc_btnNewButton_7.insets = new Insets(0, 0, 5, 5);
		gbc_btnNewButton_7.gridx = 0;
		gbc_btnNewButton_7.gridy = 4;
		panel.add(btnNewButton_7, gbc_btnNewButton_7);
		
		JButton btnNewButton_10 = new JButton("New button");
		GridBagConstraints gbc_btnNewButton_10 = new GridBagConstraints();
		gbc_btnNewButton_10.insets = new Insets(0, 0, 5, 0);
		gbc_btnNewButton_10.gridx = 1;
		gbc_btnNewButton_10.gridy = 4;
		panel.add(btnNewButton_10, gbc_btnNewButton_10);
		
		JButton btnNewButton_4 = new JButton("New button");
		GridBagConstraints gbc_btnNewButton_4 = new GridBagConstraints();
		gbc_btnNewButton_4.gridwidth = 2;
		gbc_btnNewButton_4.fill = GridBagConstraints.BOTH;
		gbc_btnNewButton_4.insets = new Insets(0, 0, 5, 0);
		gbc_btnNewButton_4.gridx = 0;
		gbc_btnNewButton_4.gridy = 5;
		panel.add(btnNewButton_4, gbc_btnNewButton_4);
		
		JButton btnNewButton_11 = new JButton("New button");
		GridBagConstraints gbc_btnNewButton_11 = new GridBagConstraints();
		gbc_btnNewButton_11.insets = new Insets(0, 0, 5, 5);
		gbc_btnNewButton_11.gridx = 0;
		gbc_btnNewButton_11.gridy = 6;
		panel.add(btnNewButton_11, gbc_btnNewButton_11);
		
		JButton btnNewButton_12 = new JButton("New button");
		GridBagConstraints gbc_btnNewButton_12 = new GridBagConstraints();
		gbc_btnNewButton_12.insets = new Insets(0, 0, 5, 0);
		gbc_btnNewButton_12.gridx = 1;
		gbc_btnNewButton_12.gridy = 6;
		panel.add(btnNewButton_12, gbc_btnNewButton_12);
		
		JButton btnNewButton_5 = new JButton("New button");
		GridBagConstraints gbc_btnNewButton_5 = new GridBagConstraints();
		gbc_btnNewButton_5.fill = GridBagConstraints.BOTH;
		gbc_btnNewButton_5.insets = new Insets(0, 0, 5, 5);
		gbc_btnNewButton_5.gridx = 0;
		gbc_btnNewButton_5.gridy = 7;
		panel.add(btnNewButton_5, gbc_btnNewButton_5);
		
		JButton btnNewButton_6 = new JButton("New button");
		GridBagConstraints gbc_btnNewButton_6 = new GridBagConstraints();
		gbc_btnNewButton_6.insets = new Insets(0, 0, 5, 0);
		gbc_btnNewButton_6.fill = GridBagConstraints.BOTH;
		gbc_btnNewButton_6.gridx = 1;
		gbc_btnNewButton_6.gridy = 7;
		panel.add(btnNewButton_6, gbc_btnNewButton_6);
		
		JButton btnNewButton_13 = new JButton("New button");
		GridBagConstraints gbc_btnNewButton_13 = new GridBagConstraints();
		gbc_btnNewButton_13.insets = new Insets(0, 0, 5, 5);
		gbc_btnNewButton_13.gridx = 0;
		gbc_btnNewButton_13.gridy = 8;
		panel.add(btnNewButton_13, gbc_btnNewButton_13);
		
		JButton btnNewButton_14 = new JButton("New button");
		GridBagConstraints gbc_btnNewButton_14 = new GridBagConstraints();
		gbc_btnNewButton_14.insets = new Insets(0, 0, 5, 0);
		gbc_btnNewButton_14.gridx = 1;
		gbc_btnNewButton_14.gridy = 8;
		panel.add(btnNewButton_14, gbc_btnNewButton_14);
		
		JButton btnNewButton_15 = new JButton("New button");
		GridBagConstraints gbc_btnNewButton_15 = new GridBagConstraints();
		gbc_btnNewButton_15.insets = new Insets(0, 0, 0, 5);
		gbc_btnNewButton_15.gridx = 0;
		gbc_btnNewButton_15.gridy = 9;
		panel.add(btnNewButton_15, gbc_btnNewButton_15);
		
		JButton btnNewButton_16 = new JButton("New button");
		GridBagConstraints gbc_btnNewButton_16 = new GridBagConstraints();
		gbc_btnNewButton_16.gridx = 1;
		gbc_btnNewButton_16.gridy = 9;
		panel.add(btnNewButton_16, gbc_btnNewButton_16);
		for(int i = 0; i < 100; i++)
			panel.add(new JLabel("TESTINGTESTING 12"));
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		
		//switches to the next card
		((CardLayout)viewPanel.getLayout()).show(viewPanel, "panel");
		
	}
}
